<template>
	<view class="detail" style="padding-top: 0rpx;">
		<view class="" style="position: relative;">
			<view class="sign" v-if="alert">预警动物</view>
			<image :src="imgurl" mode="aspectFill" style="width: 100vw;height: 400rpx;"></image>
		</view>
		<view class="" v-for="(item, index) in result" :key="index" @click="changeitem(index)">
			<view class="item-top">
				<view class="font1">
					{{ item.name }}
				</view>
				<view class="font2">
					可信度{{ (item.score * 100).toFixed(2) }}%
				</view>
			</view>
			<view class="item-b" v-if="item.show">
				<view class="font3">
					{{ item.baike_info.description }}
				</view>
				<view class="font5" @click="tobaike(item.name)">
					详细>>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { recordAdd } from "@/api/login";
export default {
	data() {
		return {
			isShangchuan: false,
			imgurl: "",
			alert: false,
			result: []
		};
	},
	onNavigationBarButtonTap(e) {
		console.log(e);
		if (e.text == "上传") {
			// recordAdd(this.result).then(res => {
			// 	console.log('上传')
			// }).catch(msg => {
			// 	console.log('上传',msg)
			// })
		}
	},

	onLoad() { },
	onShow() {
		if (uni.getStorageSync("curhistoryList")) {
			let list = uni.getStorageSync("curhistoryList");
			let index = list.length - 1;
			this.alert = list[index].alert;
			console.log("this.alert", list[index]);
			this.result = list[index].result;
			this.result.forEach((item, ii) => {
				if (ii === 0) {
					item.show = true;
				} else {
					item.show = false;
				}
			});
			this.imgurl = list[index].imgurl;
		}
	},

	methods: {
		shangchuan() {
			let that = this;
			if (this.isShangchuan) {
				uni.showToast({
					title: "不要重复上传",
					icon: "none"
				});
				return;
			}
			this.isShangchuan = true;
			uni.showLoading({
				title: "上传中..."
			});
			console.log(22222223333, this.result);
			
			recordAdd(this.result)
				.then(res => {
					setTimeout(function () {
						uni.hideLoading();
						uni.showToast({
							title: "上传成功",
							icon: "none"
						});
						that.isShangchuan = false;
					}, 800);
					console.log("上传");
				})
				.catch(msg => {
					setTimeout(function () {
						uni.hideLoading();
						that.isShangchuan = false;
					}, 800);
					console.log("上传msg");
			});
		},
		changeitem(index) {
			let list = JSON.parse(JSON.stringify(this.result));
			list.forEach((item, ii) => {
				if (ii === index) {
					item.show = true;
				} else {
					item.show = false;
				}
			});
			this.result = JSON.parse(JSON.stringify(list));
			console.log("111", this.result, index, list);
		},
		tobaike(name) {
			uni.navigateTo({
				url: "/pages/baike/index?name=" + name
			});
		}
	}
};
</script>

<style scoped lang="scss">
page {
	background-color: #f7f7f7;
}

.detail {
	box-sizing: border-box;
	background-color: #ffffff;

	.sign {
		position: absolute;
		left: 0;
		top: 0;
		width: 56px;
		border-bottom-left-radius: 10px;
		border-top-right-radius: 10px;
		height: 50rpx;
		line-height: 50rpx;
		display: inline-block;
		padding: 0rpx 20rpx;
		font-size: 26rpx;
		color: #ffffff;
		background-color: #e65538;
	}

	.item-top {
		display: flex;
		justify-content: space-between;
		line-height: 79rpx;
		height: 80rpx;
		border-bottom: 1rpx solid #eaeaea;
	}

	.font1 {
		font-size: 32rpx;
		font-weight: 700;
		margin-left: 30rpx;
	}

	.font2 {
		font-size: 28rpx;
		color: #666;
		margin-right: 30rpx;
	}

	.font3 {
		margin-left: 30rpx;
		margin-right: 30rpx;
		font-size: 28rpx;
		color: #000;
		line-height: 50rpx;
		margin-top: 16rpx;
	}

	.font5 {
		color: #4e98dc;
		text-align: right;
		font-size: 28rpx;
		padding-top: 20rpx;
		padding-right: 30rpx;
		padding-bottom: 20rpx;
		box-sizing: border-box;
		border-bottom: 1rpx solid #eaeaea;
	}
}
</style>
